<template>
	<view style="padding-bottom:50rpx;">
		<page-head :title="'优惠券'" :headtype="2"></page-head>
		<view class="tagnav">
			<view class="tagnavmain marginAuto">
				<view class="naveach" @click="navfun(1)" :class="navac == 1 ? 'navactive':''">可使用
					<view class="naveachx"></view>
				</view>
				<view class="naveach" @click="navfun(2)" :class="navac == 2 ? 'navactive':''">已使用
					<view class="naveachx"></view>
				</view>
				<view class="naveach" @click="navfun(3)" :class="navac == 3 ? 'navactive':''">已过期
					<view class="naveachx"></view>
				</view>
			</view>
		</view>
		<view class="disount">
			<discountlist :disdata="disdata" :navac="navac" @disusefun="disusefun"></discountlist>
		</view>
	</view>
</template>

<script>
	import discountlist from '../../components/discount/discountlist.vue'
	export default {
		components: {
			discountlist
		},
		data() {
			return {
				apifun:this.apifun,
				page:1,
				navac:1,
				disdata:[]
			};
		},
		onLoad() {
			this.initData()
		},
		methods: {
			disusefun(item){  // 去使用
				uni.reLaunch({
					url:'/pages/tabbar/learn'
				})
			},
			initData(){
				let type;
				if(this.navac == 1){
					type = 1
				}else if(this.navac == 2){
					type = 3
				}else if(this.navac == 3){
					type = 2
				}
				let sendData = {
					type:type,  //  1可用 2过期 3已使用
					page:this.page,
					limit:this.apifun.limit
				}
				this.apifun.unirequest('/api/coupon/getUserCouponList','post',sendData,(res)=>{
					if(res.code === 200){
						let datas = res.data;
						if(datas.data.length <= 0){
							this.page--;
							return false
						};
						this.disdata = [...this.disdata,...datas.data]
					}else{
						this.apifun.toast(res.msg)
					}
				})
			},
			navfun(type){
				if(type == this.navac){
					return false
				};
				this.page = 1;
				this.navac = type;
				this.disdata = [];
				this.initData();
			}
		},
		onPullDownRefresh() {
			this.page = 1;
			this.disdata = [];
			this.initData();
			uni.stopPullDownRefresh();
		},
		onReachBottom() {
			this.page++;
			this.initData()
		},
	};
</script>

<style scoped lang="scss">
	page{
		background: #F7F7F7;
	}
	.tagnav{
		position:sticky;
		top: 0;
		width: 100%;
		padding:15rpx 0 20rpx;
		background: #fff;
		.tagnavmain{
			width:90%;
			display: flex;
			justify-content: space-between;
			.naveach {
				position: relative;
				color: #999999;
				font-size:30rpx;
				text-align: center;
				font-weight: 600;
				.naveachx {
					position: absolute;
					bottom: -10rpx;
					left: 50%;
					background: #fff;
					width: 50rpx;
					margin-left: -25rpx;
					height: 6rpx;
					border-radius: 100rpx;
					transition: background .5s;
				}
			}
			.navactive {
				color:#333333;
				
				.naveachx {
					background: #2AB4FF;
				}
			}
		}
	}
</style>